package com.baizan.daka.ui.fragment

import com.baizan.daka.base.BasePageListFragment
import com.baizan.daka.event.ReceiveTastEvent
import com.baizan.daka.ui.contract.TaskCheckContract
import com.baizan.daka.mvp.model.bean.TaskInfoBean
import com.baizan.daka.ui.presenter.TaskCheckPresenter
import com.baizan.daka.net.BasePageResponse
import com.baizan.daka.ui.adapter.TaskCheckAdapter
import kotlinx.android.synthetic.main.frg_base_list.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class TaskCheckFragment : BasePageListFragment<TaskCheckPresenter, TaskCheckAdapter>() ,
    TaskCheckContract.View {

    override fun initPresenter(): TaskCheckPresenter? = TaskCheckPresenter(this)

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun collectEvnetBean(event: ReceiveTastEvent) {
        toRefresh()
    }
    override fun initData() {
        super.initData()
    }

    override fun initView() {
    }
    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        if(!hidden){
            toRefresh()
        }
    }
    override fun start() {
        EventBus.getDefault().register(this)
        presenter?.loadList(mCurrentPageNo)
    }

    override fun onDestroy() {
        EventBus.getDefault().unregister(this)
        super.onDestroy()
    }
    override fun onRefresh() {
        presenter?.loadList(mCurrentPageNo)
    }

    override fun onLoadMore() {
        presenter?.loadList(mCurrentPageNo)
    }

    override fun initAdapter(): TaskCheckAdapter? = TaskCheckAdapter()
    override fun loadListSuccess(data: BasePageResponse<TaskInfoBean>) {
        getDatasSuccess(data)
    }

    override fun loadListFail(fail: String) {
        getDatasFail()
    }

}